package com.mililoan.console.mvc;

import java.util.HashMap;

import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.mililoan.common.constant.RightmrgGlobe;
import com.mililoan.console.service.OnlineService;
import com.mililoan.model.system.User;

/**
 * session 接听
 * @author hozen 2014-6-26
 */
public class SessionListener implements HttpSessionListener{
    private static final Log log = LogFactory.getLog(SessionListener.class);
    
    //private static HashMap hUserName = new HashMap();//保存sessionID和username的映射
    /**以下是实现HttpSessionListener中的方法**/
    public void sessionCreated(HttpSessionEvent se){
        log.debug("SessionListener##:sessionid="+se.getSession().getId()+" 创建");
    }

    public void sessionDestroyed(HttpSessionEvent se){
    	User user = (User)se.getSession().getAttribute(RightmrgGlobe.SESSION_USER_KEY);
        log.debug("SessionListener##:sessionid="+se.getSession().getId()+" 过期");
        if(user!=null){
            HashMap statusHm = OnlineService.getStatusHm();
            statusHm.remove(user.getId()+"");
            log.debug("SessionListener##:userid ="+user.getId()+"");
        }
    }

}

